package com.bawei.hgshop.common;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;

import com.bawei.hgshop.entity.User; 

/**
 * 拦截器
 * @时间  2021-1-21  9:08:35
 *
 */
public class LoginInterceptor implements HandlerInterceptor {
	
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		 
		//  从Session当中获取用户的信息
		User loginUser = (User)request.getSession().getAttribute("loginuser");
		if(loginUser==null) {
			// 说明没有登录  不能放行
			request.getRequestDispatcher("/user/tologin").forward(request, response);  
			return false;
		}
		return true;
	}
	
}
